﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using WeaponEvalue.Logic;

namespace WeaponEvalue
{
    public partial class LogUserControl : UserControl
    {
        private List<ThreeDimension> logData = new List<ThreeDimension>();
        private Point upperLeft;
        private Point bottomRight;

        public Point UpperLeft
        {
            get { return upperLeft; }
            set { upperLeft = value; }
        }

        public Point BottomRight
        {
            get { return bottomRight; }
            set { bottomRight = value; }
        }


        public LogUserControl()
        {
            InitializeComponent();
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            if (BackgroundImage != null)
            {
                e.Graphics.DrawImage(BackgroundImage, 0, 0, Width, Height);
            }
            foreach (ThreeDimension dimension in logData)
            {
                e.Graphics.FillRegion(Brushes.Red,new Region(new Rectangle(GotoXy(dimension.x,dimension.y),new Size(2,2))));
            }
        }

        public Point GotoXy(float x, float y)
        {
            int w = Math.Abs(upperLeft.X - bottomRight.X);
            int h = Math.Abs(upperLeft.Y - bottomRight.Y);
            int xt = (int)(Math.Abs(x - upperLeft.X) / w * Width);
            int yt = (int)(Math.Abs(y - upperLeft.Y) / h * Height);
            return new Point(xt, yt);
        }

        public void AddPoint(int x,int y)
        {
            ThreeDimension threeDimension=new ThreeDimension();
            threeDimension.x =x;
            threeDimension.y = y;
            logData.Add(threeDimension);
            Invalidate();
        }

        public void AddPoint(ThreeDimension dimension)
        {
            ThreeDimension threeDimension = new ThreeDimension();
            threeDimension.x = dimension.x;
            threeDimension.y = dimension.y;
            logData.Add(threeDimension);
            Invalidate();
        }

        public void AddPointRange(List<ThreeDimension> dimensions)
        {
            logData.Clear();
            logData.AddRange(dimensions);
            Invalidate();
        }


        public void Clear()
        {
            logData.Clear();
            Invalidate();
        }

    }
}
